﻿using DLL;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem
{
    public partial class UserControl : Form
    {
        #region 变量声明
        public NursingFormSystem.NurFormsService.NursingForm formService = new NursingFormSystem.NurFormsService.NursingForm();
        NursingFormSystem.WebReference2.FunctionAndPermissions WebService = new NursingFormSystem.WebReference2.FunctionAndPermissions();
        string[] user;//当前的登录信息
        #endregion

        #region 构造函数
        public UserControl(string[] UserParam)
        {
            InitializeComponent();
            user = UserParam;
        }
        #endregion

        #region 查询
        private void Btn_ChaXun_Click(object sender, EventArgs e)
        {
            DateTime startdt = DateTime.Now.AddDays(-30);
            DateTime enddt = DateTime.Now;
            DataTable patients = WebService.GetPatientInfoByType(startdt, enddt, 1, "", user[2], false).D;
            DataTable patients01 = WebService.GetPatientInfoByType(startdt, enddt, 3, "", user[2], false).D;
            if (patients01 != null && patients != null)
            {
                patients.Merge(patients01);
            }
            if (patients01 != null && patients == null)
            {
                patients = patients01;
            }
            gridControl1.DataSource = patients;
            if (patients == null) return;
            StringBuilder conditions = new StringBuilder();
            conditions.Append("1=1");
            if (!string.IsNullOrEmpty(text_ZhuYuanHao.Text))
                conditions.AppendFormat(" AND PATIENT_ID = '{0}'", text_ZhuYuanHao.Text);
            if (!string.IsNullOrEmpty(text_XingMing.Text))
                conditions.AppendFormat(" AND PATIENT_NAME LIKE '%{0}%'", text_XingMing.Text);
            if (!string.IsNullOrEmpty(comboBox_HuLiJiBie.Text))
                conditions.AppendFormat(" AND NURSING LIKE '%{0}%'", comboBox_HuLiJiBie.Text);
            DataTable newdt = new DataTable();
            newdt = patients.Clone();
            DataRow[] rows = patients.Select(conditions.ToString());
            foreach (DataRow row in rows)
            {
                newdt.Rows.Add(row.ItemArray);
            }
            gridControl1.DataSource = newdt;
        }
        #endregion

        #region 确定
        private void Btn_BaoCun_Click(object sender, EventArgs e)
        {

        }
        #endregion
    }
}


